package com.ruicar.afs.cloud.afscase.channel.controller;

import com.ruicar.afs.cloud.afscase.channel.entity.Blacklist;
import com.ruicar.afs.cloud.afscase.channel.service.BlacklistService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @Author Ice
 * @Date 2020/06/10
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/black")
@Api(value = "black", description = "黑名单管理模块")
public class BlacklistController {
    private static final Logger logger = LoggerFactory.getLogger(BlacklistController.class);

    private final BlacklistService blacklistService;

    @Transactional
    @PostMapping("/save")
    @ApiOperation(value = "保存黑名单数据数据")
    public IResponse save(@RequestBody Blacklist blacklist) throws ParseException {
        Blacklist c = blacklistService.getById(blacklist.getId());
        if (c == null) {
            blacklistService.save(blacklist);
        } else {
            blacklistService.updateById(blacklist);
        }
        return IResponse.success("成功！");
    }
}
